package leetcode.weekly.week312;

import java.util.ArrayList;
import java.util.List;

import leetcode.helper.H;

//Solution3Test
public class Solution3 {

	public List<Integer> goodIndices(int[] nums, int k) {
		int len = nums.length;
		int[] down = new int[len];
		down[0] = 1;
		for (int i = 1; i < down.length; i++) {
			if (nums[i] <= nums[i - 1]) {
				down[i] = down[i - 1] + 1;
			} else {
				down[i] = 1;
			}
		}
		int[] up = new int[len];
		up[len - 1] = 1;
		for (int i = len - 2; i >= 0; i--) {
			if (nums[i] <= nums[i + 1]) {
				up[i] = up[i + 1] + 1;
			} else {
				up[i] = 1;
			}
		}
		List<Integer> ans = new ArrayList<>();
		for (int i = k; i < len - k; i++) {
			if (down[i - 1] >= k && up[i + 1] >= k) {
				ans.add(i);
			}
		}
		return ans;
	}

}
